package studentManage.D_Dao;

import studentManage.E_Domain.Student;

import java.util.ArrayList;

public class otherStudentDao implements baseStudentDao {
    private static ArrayList<Student> stus = new ArrayList();

    public boolean addStudent(Student stu) {
        stus.add(stu);
        return true;

    }

    // 查看学生方法
    public Student[] findAllStudent() {
        Student[] s = new Student[stus.size()];
        for (int i = 0; i < stus.size(); i++) {
            s[i] = stus.get(i);
        }
        return s;
    }

    public void deleteStudentById(String delId) {

       stus.remove(delId);
    }

    public int getIndex(String delId) {
        int index = -1;
        for (int i = 0; i < stus.size(); i++) {
            Student stu = stus.get(i);
            if (stu != null && stu.getId().equals(delId)) {
                index = i;
                break;
            }
        }
        return index;
    }

    public void updateStudent(String updateId, Student newStu) {
        // 1. 查找updateId, 在容器中的索引位置
        int index = getIndex(updateId);
        // 2. 将该索引位置, 使用新的学生对象替换
        stus.set(index,newStu);
    }

}
